﻿@{
    ViewBag.Title = "Danh sách luân chuyển chai";
    var url = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
    string PartnerName = string.Empty;
}
<script>
    app.controller('ProductMovementController', function ($scope, $compile, $http, $filter, service) {
        $scope.load = function (page) {
            if (page === 0 || (page > $scope.pageCount && $scope.pageCount > 0))
                return;

            $scope.checkedList = [];
            $scope.checkedObj = [{}];

            var url = '@url' + '@Url.Action("ProductMovementApi", "Api")';
            $http.get(url, {
                params: {
                    pageNumber: page,
                    orderBy: $scope.orderBy,
                    orderDirection: $scope.orderDirection,
                    barCode: $scope.barCode,
                    partnerName: $scope.partnerName,
                    datefrom: '',//$scope.productCode,
                    dateto: '',//$scope.productCode,
                }
            })
                .success(function (data) {
                    $scope.productMovements = data.ProductMovements;
                    $scope.productCode = data.ProductMovements.length;
                    service.setCommonData($scope, data, data.ProductMovements);
                    stoploading($('#content'));
                })
                .error(function (data) {
                    stoploading($('#content'));
                    service.showModal($scope, $compile, 'error', data.InnerException.InnerException);
                });
        };

        $scope.setSelected = function (id) {
            service.setSelected($scope, id);
        };

        $scope.check = function (id) {
            $scope.checkedObj[id] = !$scope.checkedObj[id];
        };

        $scope.setSelectedAll = function () {
            service.setSelectedAll($scope);
        };

        $scope.refresh = function (keyCode) {
            if (keyCode == undefined || keyCode === 13)
                $scope.load($scope.pageNumber);
        };

        $scope.clearrefresh = function () {
            $scope.barCode = '';
            $scope.partnerName = '';
            $scope.load($scope.pageNumber);
        };

        $scope.sort = function (ob) {
            service.setSortingValue($scope, ob);
            $scope.load($scope.pageNumber);
        };
        $scope.orderBy = 'Barcode';
        $scope.orderDirection = 'ascending';
        $scope.barCode = '';
        $scope.partnerName = '';

        $scope.checkedList = [];
        $scope.checkedObj = [{}];
        $scope.load(1);
    });
</script>
<div ng-controller="ProductMovementController">
    @Html.Partial("_PageHeader")
    @Html.Partial("_ListViewHeader")

    <div id="content" class="content row">
        <div class="panel-body">
            <div id="search">
                <div class="row" style="margin-right: 0px">
                    <div class="col-lg-2">
                        @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Barcode"},
                        {"Model", "barCode"},
                        {"Name", "barCode"},
                    })
                    </div>
                    <div class="col-lg-2">
                        @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Tên khách hàng"},
                        {"Model", "partnerName"},
                        {"Name", "partnerName"},
                    })
                    </div>
                    <div class="col-lg-2" style="clear: both">
                        @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "Từ ngày"},
                        {"Model", "datefrom"},
                        {"Name", "datefrom"}
                    })
                    </div>
                    <div class="col-lg-2">
                        @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                    {
                        {"Text", "đến"},
                        {"Model", "dateto"},
                        {"Name", "dateto"}
                    })
                    </div>
                    @Html.Partial("_Search")
                </div>
            </div>
            <div class="table-responsive">
                @Html.Partial("_Toolbar_PagedList")
                <table id="data" class="table table-striped table-bordered table-hover">
                    <colgroup>
                        <col style="width: 100px" />
                        <col style="width: 120px" />
                        <col style="width: 120px" />
                        <col />
                        <col style="width: 120px" />
                        <col style="width: 100px" />
                    </colgroup>
                    <thead>
                        <tr>
                            <th ng-click="sort('Barcode')">Barcode
                                <div ng-class="orderBy != 'Barcode' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>
                            <th ng-click="sort('ProductCode')">MS chai
                                <div ng-class="orderBy != 'ProductCode' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>                            
                            <th ng-click="sort('DateFrom')">Ngày Giao
                                <div ng-class="orderBy != 'DateFrom' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>
                            <th ng-click="sort('PartnerName')">Khách hàng
                                <div ng-class="orderBy != 'PartnerName' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>
                            <th ng-click="sort('DateTo')">Ngày Nhận
                                <div ng-class="orderBy != 'DateTo' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>
                            <th ng-click="sort('Expired')">Niên hạn
                                <div ng-class="orderBy != 'Expired' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                            </th>                            
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-hide="totalItemOnPage == 0" ng-repeat="item in items" >                            
                            <td>{{item.Barcode}}</td>
                            <td>{{item.ProductCode}}</td>
                            <td class="center">{{item.DateFrom | date:'dd/MM/y'}}</td>
                            <td>{{item.PartnerName}}</td>                            
                            <td class="center">{{item.DateTo | date:'dd/MM/y'}}</td>
                            <td class="center">{{item.Expired | date:'dd/MM/y'}}</td>                            
                        </tr>
                        <tr ng-show="totalItemOnPage == 0">
                            <td colspan="100">Không có dữ liệu
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
